package com.edu.app.mapper.linkmappers;

import com.edu.app.bean.core.SysRole;
import com.edu.app.bean.linkbeans.SysUserRole;
import com.edu.app.util.AppBaseMapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface SysUserRoleMapper extends AppBaseMapper<SysUserRole> {
    @Select("SELECT t3.* FROM S_USER t1 INNER JOIN S_USER_ROLE t2 on t1.ID = t2.USER_ID INNER " +
            "JOIN S_ROLE t3 on t2.ROLE_ID = t3.ID " +
            "WHERE t1.id = #{id};")
    List<SysRole> getRoleListByUserId(Integer id);

    //注：传参数到Mapper层，当参数超过两个以上的时候，注意使用@Param标注
    @Select("SELECT * FROM S_USER_ROLE WHERE user_id = #{user_id} and role_id = #{role_id}")
    SysUserRole getUserRole(@Param("user_id") Integer user_id, @Param("role_id") Integer role_id);

    @Select("DELETE FROM S_USER_ROLE WHERE user_id = #{user_id}")
    Integer deleteUserRoleByUserId(Integer user_id);

    @Select("DELETE FROM S_USER_ROLE WHERE role_id = #{role_id}")
    Integer deleteUserRoleByRoleId(Integer role_id);
}
